package com.yunti.yntk.util;

import java.math.BigDecimal;

public class AngleUtils {
//    static String angelformat(double angel){
//        StringBuffer stringBuffer = new StringBuffer();
//        stringBuffer.append((int)angel);
//        stringBuffer.append("°");
//        stringBuffer.append((angel-(int)angel)*60);
//        stringBuffer.append("'");
//        stringBuffer.append((angel-(int)angel)*60);
//        return stringBuffer.toString();
//    }

    static java.text.NumberFormat nf = java.text.NumberFormat.getInstance();

    static {
        nf.setGroupingUsed(false);
    }

    public static String changeToDFMArray(double du) {


        Integer[] dfmArray = new Integer[3];//[0] 度 ，[1] 分 ,[2] 秒
        try {
            //double dd = Convert.ToDouble(str);
            String str = new BigDecimal(du + "").toString();
            int p = str.indexOf(".");
            int dt = Integer.parseInt(str.substring(0, p));
            du = du - dt;
            double M = du * 60;
            int mt = (int) M;
            M = (M - mt) * 60;
            if (Math.abs(M - 60) < 0.001) {//秒精确到小数点后三位，小于0.001向前进位，秒为0，分加1，分为60，度加1
                M = 0;
                mt = mt + 1;
            }
            if (mt == 60) {
                dt = dt + 1;
                mt = 0;
            }
            dfmArray[0] = dt;
            dfmArray[1] = mt;
            dfmArray[2] = (int) Math.round(M);// 四舍五入 小数点前整数进位
        } catch (Exception e) {

        }
        return dfmArray[0] + "°" + dfmArray[1] + "'" + dfmArray[2] + "\"";
    }

    public static double changeTodouble(double angel) {
        double result = angel / 10.0;
        result = result / 3600;
        return result;
    }
}
